package com.wanmait.community.controller;

import com.wanmait.community.aop.OperationLogInfo;
import com.wanmait.community.entity.RepairFollow;
import com.wanmait.community.mapper.RepairFollowMapper;
import com.wanmait.community.service.RepairFollowService;
import com.wanmait.community.util.AjaxResult;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import javax.annotation.Resource;

@RestController
@RequestMapping("repairFollow")
public class RepairFollowController {
    @Resource
    private RepairFollowService repairFollowService;
    @Autowired
    private RepairFollowMapper repairFollowMapper;
    @PostMapping("insert")//添加回访记录
    @OperationLogInfo("业主添加或修改回访记录")
    public AjaxResult insert(@RequestBody RepairFollow repairFollow) {
        /*在这里根据传过来的repairFollow对象的complainId去数据库查是否有这个对象，
        * 如果是首次添加，查出来为null，就去添加；
        * 如果不是null表示不为空，即首次不满意，再次维修后第二次提交回访反馈，
        * 就去修改*/
        RepairFollow repairFollowCheckNull = repairFollowMapper.selectByComplaintId(repairFollow.getComplaintId());
        if(repairFollowCheckNull == null) {//首次添加
            repairFollowService.insertRepairFollowByRepairFollow(repairFollow);
            return AjaxResult.success();
        }
        if(repairFollowCheckNull!= null){
            repairFollowService.updateRepairFollowByComplaintId(repairFollow);
            return AjaxResult.success();
       }
        return AjaxResult.success();
    }
}
